<template>
	<view>
		<zmm-watermark :watermark="userStore.watermark" v-if="userStore.watermark"></zmm-watermark>
		<view class="content detail">
			<!--销售信息-->
			<view class="detail-item">
				<uni-section title="销售信息" type="line"></uni-section>
				<view class="detail-content">
					<view class="detail-text">姓名：<text>{{info.name}}</text></view>
					<view class="detail-text">平台用户：<text>{{arrText(allSalesList, info.userId)}}</text></view>
					<view class="detail-text">上级：<text>{{arrText(allLeaderList, info.parentUserId)}}</text></view>
					<view class="detail-text">平台角色：<text>{{info.roleName}}</text></view>
					<view class="detail-text">默认仓库：<text>{{`${info.warehouseName}(${info.warehouseId})`}}</text></view>
					<view class="detail-text">电话：<text>{{info.phone}}</text></view>
					<view class="detail-text">区域：<text>{{info.area}}</text></view>
					<view class="detail-text">推荐码：<text>{{info.recommendCode}}</text></view>
					<view class="detail-text">crm岗位：<text>{{info.postName}}</text></view>
					<view class="detail-text">crm角色：<text>{{arrText(managerList, info.manager)}}</text></view>
					<view class="detail-text">积分：<text>{{info.integral}}</text></view>
					<view class="detail-text">创建时间：<text>{{info.createTime}}</text></view>
					<view class="detail-text">备注：<text>{{info.remark}}</text></view>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app';
import { computed, onMounted, ref } from 'vue';
import { tab, auth, modal } from "@/plugins"
import { getTitle } from "@/utils/getter"
import { checkPermi, checkRole, checkOnlyPermi, checkOnlyRole } from "@/utils/permission"
import { salesmanDetail } from "@/api/erp_api/sale"
import { getUserAllSales, getUserAllLeader, getUserPostsRoles } from "@/api/system/user"
import { allProvince } from "@/api/erp_api/region"
import { warehouse } from "@/api/erp_api/warehouse"
import { copyText, arrText, previewImg } from '@/utils/ty.js';
import { managerList } from '@/utils/config.js'
import useUserStore from '@/store/modules/user'

	const userStore = useUserStore()
	onLoad(async (option) => {
		if (option.id) {
			id.value = option.id
			// getWarehouse()
			getAllLeader()
			getAllSales()
			getDetail()
		}
	})
	
	// 获取仓库
	const warehouseList = ref([])
	const getWarehouse = () => {
		return warehouse().then(res => {
			warehouseList.value = res.rows.map(item => {
				return {
					...item,
					value: item.id,
					text: `${item.name}(${item.id})`
				}
			}) || []
		})
	}
	
	// 平台用户
	const allSalesList = ref([])
	const getAllSales = () => {
		return getUserAllSales().then(res => {
			allSalesList.value = res.data.map(item => {
				return {
					...item,
					value: item.userId,
					text: `${item.nickName}(${item.userName})`
				}
			}) || []
		})
	}
	
	// 平台上级
	const allLeaderList = ref([])
	const getAllLeader = () => {
		return getUserAllLeader().then(res => {
			allLeaderList.value = res.data.map(item => {
				return {
					...item,
					value: item.userId,
					text: `${item.nickName}(${item.userName})`
				}
			}) || []
		})
	}
	
	// 数据查询
	const id = ref('')
	const info = ref({})
	const isLoading = ref(false)
	
	const getDetail = () => {
		const params = {
			id: id.value
		}
		isLoading.value = true
		uni.showLoading({
			title: '数据加载中...'
		})
		salesmanDetail(params).then(res => {
			info.value = res.data || {}
			isLoading.value = false
			uni.hideLoading()
    }).catch(() => {
			isLoading.value = false
			uni.hideLoading()
		})
	}
	
</script>

<style scoped lang="scss">
</style>
